package cn.gcjxsc.service.integral;

import cn.gcjxsc.data.vo.salesman.BankCardVo;
import cn.gcjxsc.entity.salesman.BankCard;
import cn.gcjxsc.form.BankCardForm;
import cn.gcjxsc.repository.salesaman.BankCardRepository;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author pumbaa
 * @since 1.0
 */
@Service
public class BankCardService {
    @Autowired
    private BankCardRepository bankCardRepository;

    /**
     * @param form
     * @return
     */
    public BankCard newBankCard(BankCardForm form) {
        BankCard bankCard = new BankCard();
        bankCard.setBankCardNo(form.getCardNo());
        bankCard.setBankBranchName(form.getBranchName());
        bankCard.setBankName(form.getBankName());
        bankCard.setCardHolder(form.getCardHolder());
        bankCard.setMemberId(form.getMemberId());
        return bankCard;
    }

    /**
     * 添加银行卡
     *
     * @param bankCard 银行卡信息
     * @return
     */
    @Transactional
    public BankCard saveBankCard(BankCard bankCard) {
        return bankCardRepository.save(bankCard);
    }

    /**
     * 查询业务员的银行卡片信息
     *
     * @param memberId 会员id
     * @return
     */
    public List<BankCard> findListByMemberId(Integer memberId) {
        return bankCardRepository.findByMemberId(memberId);
    }

    public BankCard findById(Integer id) {
        return bankCardRepository.findOne(id);
    }

    public BankCardVo convert(BankCard bankCard) {
        BankCardVo vo = new BankCardVo();
        BeanUtils.copyProperties(bankCard, vo);
        return vo;
    }
}
